package com.matt.service.impl;

import com.matt.domain.teaching.TeachingMaterial;
import com.matt.commons.exception.BusinessException;

import com.matt.foundation.model.ErrorCode;
import com.matt.repository.teaching.TeachingMaterialRepository;
import com.matt.service.TeachingMaterialService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/7/11
 * *******************************
 */
@Service
public class TeachingMaterialServiceImpl implements TeachingMaterialService {

  /*  @Value("${matt.robot.img.url}")
    private String matt_robot_img_url;*/

    @Autowired
    private TeachingMaterialRepository materialRepository;

    @Override
    public TeachingMaterial getByMaterialId(Long materialId) {
        TeachingMaterial material = materialRepository.getOne(materialId);
        if (Objects.isNull(material))
            throw new BusinessException(ErrorCode.MATERIAL_NOT_EXIST, "资料不存在！");

        if (StringUtils.isNotBlank(material.getMedia()))
            material.setMedia( material.getMedia());
        if (StringUtils.isNotBlank(material.getThumb()))
            material.setThumb( material.getThumb());
        material.setContent(material.getContent().replace("\"","\'"));
        return material;

    }
}
